package speelotheek;

import speelotheek.components.Database;
import speelotheek.components.Frame;
import speelotheek.components.TabbedPane;
import speelotheek.configs.Config;
import speelotheek.views.Main;

import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.UIManager;

public class Application 
{
	protected static Frame frame;
	protected static TabbedPane tabbedpane;
	protected static Main main;
	
	private static Config config;
	
	/**
	 * @param args
	 */
	public static void main(String[] args)
	{		
		try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} 
		catch (Throwable e) {
			e.printStackTrace();
		}
		EventQueue.invokeLater(new Runnable() {
			public void run()
			{
				try {
					config = new Config();
					
					// LETS OPEN THE DATABASE FIRST !!!
				    if (!Database.openConnection(config.server, config.database, config.user, config.password)) {
				    	System.out.println("Geen verbinding met de database");
				    	//System.exit(0);
				    }
					
					frame = new Frame();
					main = new Main();					
					
					frame.setLocationRelativeTo(null); // Dialog scherm in het midden
					frame.setVisible(true);
					frame.getContentPane().add(main);
					
					main.btnMainContinue.addActionListener(new ActionListener() {						
						@Override
						public void actionPerformed(ActionEvent e) {
							tabbedpane = new TabbedPane();
							frame.getContentPane().remove(main);
							frame.getContentPane().add(tabbedpane);
							frame.getContentPane().invalidate();
							frame.getContentPane().validate();
						}
					});
				} 
				catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
		
	}

}
